package com.etang.homeproject2.slice;

import com.etang.homeproject2.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.ProgressBar;
import ohos.agp.components.Text;
import ohos.agp.window.service.WindowManager;

public class MainAbilitySlice extends AbilitySlice {

    private int number = 0;
    private ProgressBar pg_login_progressbar;
    private Text tv_login_number;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        //全屏
//        getWindow().addFlags(WindowManager.LayoutConfig.MARK_FULL_SCREEN);
        super.setUIContent(ResourceTable.Layout_ability_main);
        //绑定控件
//        initView();
        //开启进度条线程
//        start_progressbar(intent);
    }

    private void start_progressbar(Intent intent) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (number < 150) {
                    try {
                        Thread.sleep(20);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    number++;
                    getUITaskDispatcher().asyncDispatch(new Runnable() {
                        @Override
                        public void run() {
                            pg_login_progressbar.setProgressValue(number);
                            if (number < 100) {
                                tv_login_number.setText(String.valueOf(number) + "%");
                            } else {
                                tv_login_number.setText("100%");
                            }
                        }
                    });
                    if (number > 140) {
                        present(new WeleComeAbilitySlice(), intent);
                        stopAbility(intent);
                    }
                }
            }
        }).start();
    }


    private void initView() {
        tv_login_number = (Text) findComponentById(ResourceTable.Id_tv_loading_number);
        pg_login_progressbar = (ProgressBar) findComponentById(ResourceTable.Id_pg_login_progressbar);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
